import fs from 'fs'
import https from 'https'
import path from 'path'

const downloads = [
  {
    url: 'https://unpkg.com/nes.css@latest/css/nes.min.css',
    dest: '../public/assets/css/nes.min.css'
  },
  {
    url: 'https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap',
    dest: '../public/assets/fonts/press-start-2p.woff2'
  }
]

downloads.forEach(({ url, dest }) => {
  https.get(url, (res) => {
    const filePath = path.resolve(__dirname, dest)
    const fileStream = fs.createWriteStream(filePath)
    res.pipe(fileStream)
    fileStream.on('finish', () => {
      fileStream.close()
      console.log(`Downloaded: ${dest}`)
    })
  })
}) 